package com.ldj.rocketmq.producer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * User: ldj
 * Date: 2023/5/4
 * Time: 15:45
 * Description: No Description
 */
@Slf4j
@Component
public class StreamProducer {

    @Autowired
    private StreamBridge streamBridge;

    public void sendMessage(String message) {
        Message<String> payload = MessageBuilder.withPayload(message).build();
        Map<String, Object> map = new LinkedHashMap<>();
        map.put("name", "ldk");
        map.put("age", 20);
        streamBridge.send("demoChannel-out-0", MessageBuilder.createMessage(payload, new MessageHeaders(map)));
    }

}
